package zb.fix.client.data;

import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import quickfix.Message;
import quickfix.field.Account;
import quickfix.field.ClOrdID;
import quickfix.field.MassStatusReqID;
import quickfix.field.MassStatusReqType;
import quickfix.field.OrdType;
import quickfix.field.OrderQty;
import quickfix.field.OrigClOrdID;
import quickfix.field.Price;
import quickfix.field.Side;
import quickfix.field.Symbol;
import quickfix.field.TransactTime;
import quickfix.fix50sp2.NewOrderSingle;
import quickfix.fix50sp2.OrderCancelRequest;
import quickfix.fix50sp2.OrderMassStatusRequest;
import zb.fix.entity.request.UserApi;
import zb.fix.kits.EncryDigestUtil;

@NoArgsConstructor
@RequiredArgsConstructor
public class TradingRequest {
	private @NonNull UserApi userApi;

	/** 下单 */
	public Message order() {
		NewOrderSingle order = new NewOrderSingle();
		order.set(new OrdType('1'));// 判断是否开启杠杆0.现货,1.杠杠

		order.set(new ClOrdID("zb_"));// 客户选择的UUID识别订单
		order.set(new Symbol("zb_qc"));
		order.set(new Side('1'));// 1.buy,0.sell
		order.set(new Price(10));
		order.set(new OrderQty(1));// 订单量
		order.set(new TransactTime());
		String sing = EncryDigestUtil.digest(userApi.getSecretKey());
		System.out.println(""+sing);
		order.set(new Account(userApi.getApikey()+","+sing));
		
		
		return order;
	}

	/** 订单状态请求 */
	public Message getOrder() {
		OrderMassStatusRequest order = new OrderMassStatusRequest();
		order.set(new Symbol("121212/CNY"));
		order.set(new MassStatusReqID("2123413"));// 查询的订单ID
		order.set(new MassStatusReqType(MassStatusReqType.STATUS_FOR_ALL_ORDERS));
		order.set(new Account(userApi.getApikey()+","+EncryDigestUtil.digest(userApi.getSecretKey())));
		
		return order;
	}

	/** 取消订单请求 */
	public Message cancel() {
		OrderCancelRequest order = new OrderCancelRequest();
		order.set(new ClOrdID("2"));// 客户选择的UUID识别订单
		order.set(new OrigClOrdID("1231234"));// 订单编号
		order.set(new Side('1')); // 1买入;2卖出
		order.set(new Symbol("btc_qc"));
		order.set(new TransactTime());
		order.set(new Account(userApi.getApikey()+","+EncryDigestUtil.digest(userApi.getSecretKey())));

		return order;
	}
}
